package com.example.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DataUtils {
    public static Connection getConn(){
        Connection conn =null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(
                    "jdbc:mysql://10.47.164.204:3306/news?useSSl=false",
                    "root",
                    "sa123"
            );
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return conn;
    }

    public static void closeConnection(Connection conn) {
        try {
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main(String[] args) {
       Connection conn =DataUtils.getConn();
       if (conn!=null){
           System.out.println("成功");
       }else {
           System.out.println("失败");
       }
       DataUtils.closeConnection(conn);
    }
}
